package com.ruoyi.performance.service.impl;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.performance.domain.PerfTarget;
import com.ruoyi.performance.dto.PerfTargetDto;
import com.ruoyi.performance.mapper.PerfTargetMapper;
import com.ruoyi.performance.service.PerfTargetService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author YL
 * @date 2020-07-22
 * @description 考核细项指标Service业务层处理
 */
@Service
public class PerfTargetServiceImpl implements PerfTargetService {

    @Resource
    private PerfTargetMapper perfTargetMapper;

    /**
     * 查询考核细项指标
     * 
     * @param id 考核细项指标ID
     * @return 考核细项指标
     */
    @Override
    public List<PerfTargetDto> selectPerfTargetById(int id){
        return perfTargetMapper.selectPerfTargetById(id);
    }

    /**
     * 查询考核细项指标列表
     * 
     * @param perfTargetDto 考核细项指标
     * @return 考核细项指标
     */
    @Override
    public List<PerfTargetDto> selectPerfTargetList(PerfTargetDto perfTargetDto){
        return perfTargetMapper.selectPerfTargetList(perfTargetDto);
    }

    /**
     * 新增考核细项指标
     * 
     * @param perfTarget 考核细项指标
     * @return 结果
     */
    @Override
    public int insertPerfTarget(PerfTarget perfTarget){
        String username = ServletUtils.getRequest().getHeader(Constants.CURRENT_USERNAME);
        String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        perfTarget.setStatus("0");
        perfTarget.setCreateBy(username);
        perfTarget.setCreateTime(now);
        return perfTargetMapper.insertPerfTarget(perfTarget);
    }

    /**
     * 修改考核细项指标
     * 
     * @param perfTarget 考核细项指标
     * @return 结果
     */
    @Override
    public int updatePerfTarget(PerfTarget perfTarget){
        String username = ServletUtils.getRequest().getHeader(Constants.CURRENT_USERNAME);
        String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        perfTarget.setUpdateBy(username);
        perfTarget.setUpdateTime(now);
        return perfTargetMapper.updatePerfTarget(perfTarget);
    }

    /**
     * 删除考核细项指标信息
     * 
     * @param id 考核细项指标ID
     * @return 结果
     */
    @Override
    public int deletePerfTargetById(int id)
    {
        return perfTargetMapper.deletePerfTargetById(id);
    }
}
